#include "Color.h"

#include <gl.h>

namespace Lame3d
{
	Color::Color(float r, float g, float b, float a)
			: Red(r), Blue(b), Green(g), Alpha(a)
	{
	}
	
	Color::Color(const Color &c)
			: Red(c.Red), Blue(c.Blue), Green(c.Green), Alpha(c.Alpha)
	{
	}
	
	Color::~Color()
	{
	}
	
	SDL_Color Color::SDLColor() const
	{
		SDL_Color c;
		c.r = (Uint8)(255*Red);
		c.b = (Uint8)(255*Blue);
		c.g = (Uint8)(255*Green);
		return c;
	}
	
	bool Color::operator<(const Color &c) const
	{
		if(Red == c.Red) {
			if(Green == c.Green) {
				if(Blue == c.Blue) {
					return Alpha < c.Alpha;
				} else {
					return Blue < c.Blue;
				}
			} else {
				return Green < c.Green;
			}
		} else {
			return Red < c.Red;
		}
	}
	
	Color glGetColor()
	{
		float col[4];
		glGetFloatv(GL_CURRENT_COLOR, col);
		return Color(col[0], col[1], col[2], col[3]);
	}
	
	void glSetColor(const Color &c)
	{
		glColor4f( c.Red, c.Green, c.Blue, c.Alpha );
	}
}
